#!/usr/bin/env python
# -*- encoding: utf-8 -*-
'''
Created on 2014年9月5日

@author: monstar-216
'''

from datetime import datetime, date,time,timedelta
import calendar

def get_user_walking_distance(login_count, reset_date_last, login_date):
    if login_count <=7:
        correction_A = 5 * login_count
    else:
        correction_A = 35
    
    login_to_reset = (login_date - reset_date_last).days
    print 'login_to_reset,',login_to_reset
    if login_count > 7:
        if login_count < login_to_reset:
            correction_B = login_count -7
        else:
            if login_count - login_to_reset >=7:
                correction_B = login_to_reset
            else:
                correction_B = login_count -7
    else:
        correction_B = 0
        
    return correction_A + correction_B

def get_reset_date(login_date):
    reset_day = 10
    year = login_date.year
    month = login_date.month
    day = login_date.day
    if reset_day < day <= 31:
        reset_date_last = date(year,month,reset_day)
        reset_date_tomonth = date(year,month+1,reset_day)
    else:
        reset_date_last = date(year,month-1,reset_day)
        reset_date_tomonth = date(year,month,reset_day)
    return reset_date_last

def add_months(dt,months):
    month = dt.month - 1 + months
    year = dt.year + month / 12
    month = month % 12 + 1
    day = min(dt.day,calendar.monthrange(year,month)[1])
    return dt.replace(year=year, month=month, day=day)

if __name__ == '__main__':
    login_count = 8
    login_date = date(2014,10,16)
    reset_date_last = get_reset_date(login_date)
    point = get_user_walking_distance(login_count, reset_date_last, login_date)
    print 'today walk:',point
    
    d = date(2014,1,31)
    print add_months(d, 1)
    
    
    
    